import { Killer } from "../../funcObj/interface/HealthPoint";
import Player from "../../player/Player";
import DestructibleFacility from "../DestructibleFacility";

const { ccclass, property } = cc._decorator;

/**
 * 卫星 获取所有视野
 */
@ccclass
export default class Satellite extends DestructibleFacility {

    @property(cc.Sprite)
    show: cc.Sprite = null;

    @property(cc.Animation)
    sateAnimation: cc.Animation = null;

    @property(cc.Animation)
    spin: cc.Animation = null

    @property([cc.SpriteFrame])
    frames: cc.SpriteFrame[] = [];

    init(player: Player): void {
        super.init(player);
        this.show.spriteFrame = this.frames[player.playerId];
        this.sateAnimation.play();

        this.spin.node.active = true;
        this.spin.play();
        this.spin.on(cc.Animation.EventType.FINISHED, () => {
            this.spin.node.active = false;
            this.spin.targetOff(this);
        }, this)

        this.player.showAllView = true;
    }

    die(killer: Killer): void {
        super.die(killer);
        this.spin.targetOff(this);
        this.player.showAllView = false;
    }

}
